package com.ocom.company.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocom.common.constant.CompanyServiceUrl;
import com.ocom.common.entity.company.EntityProductSuggestion;
import com.ocom.common.request.company.ProductSuggestionPageRequest;
import com.ocom.common.request.company.ProductSuggestionRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.company.service.ProductSuggestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class ProductSuggestionController {


    @Autowired
    private ProductSuggestionService productSuggestionService;


    @GetMapping("/product_suggestion/list")
    public Result productSuggestionList(@RequestParam("comId") Long comId,@RequestParam("userId") Long userId, @RequestParam("page") int page,
                                 @RequestParam("size") int size) {
        PageHelper.startPage(page, size);
        List<EntityProductSuggestion> entityProductSuggestions = productSuggestionService.productSuggestionList(comId,userId);
        return ResultUtil.success(new PageInfo<>(entityProductSuggestions));
    }

    @PostMapping("/product_suggestion/create")
    public Result productSuggestionList(@RequestParam("comId") Long comId,@RequestBody EntityProductSuggestion entityProductSuggestion) {

        productSuggestionService.productSuggestionCreate(comId,entityProductSuggestion);
        return ResultUtil.success();
    }

    /**
     * 产品建议列表
     * @param request
     * @return
     */
    @PostMapping(CompanyServiceUrl.URL_productSuggestionPage)
    public Result productSuggestionPage(@RequestBody ProductSuggestionPageRequest request) {
        PageHelper.startPage(request.getPage(), request.getSize());
        List<EntityProductSuggestion> entityProductSuggestions = productSuggestionService.productSuggestionPage();
        return ResultUtil.success(new PageInfo<>(entityProductSuggestions));
    }

    /**
     * 修改产品建议列表
     * @param request
     * @return
     */
    @PostMapping(CompanyServiceUrl.URL_productSuggestionUpdate)
    public Result productSuggestionUpdate(@RequestBody ProductSuggestionRequest request) {
        productSuggestionService.productSuggestionUpdate(request);
        return ResultUtil.success();
    }

    /**
     * 删除产品建议
     * @param request
     * @return
     */
    @PostMapping(CompanyServiceUrl.URL_productSuggestionDelete)
    public Result productSuggestionDelete(@RequestBody ProductSuggestionRequest request) {
        productSuggestionService.productSuggestionDelete(request);
        return ResultUtil.success();
    }



}
